package c.j.a.d.b.c;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.text.TextUtils;
import android.util.SparseArray;
import c.j.a.d.b.e.t;
import com.huawei.hms.jos.games.ranking.RankingConst;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;

/* compiled from: SqlDownloadCache */
public class e extends c.j.a.d.b.c.c.a implements t {
    public static volatile SQLiteDatabase f;
    public i b;
    public i c;
    public volatile boolean d;
    public b e = null;

    /* compiled from: SqlDownloadCache */
    public class a implements Runnable {
        public final /* synthetic */ com.ss.android.socialbase.downloader.g.c a;

        public a(com.ss.android.socialbase.downloader.g.c cVar) {
            this.a = cVar;
        }

        public void run() {
            e eVar = e.this;
            com.ss.android.socialbase.downloader.g.c cVar = this.a;
            synchronized (eVar) {
                if (cVar == null) {
                    return;
                }
                Object obj;
                try {
                    obj = null;
                    if (eVar.b(cVar.g0()) != null) {
                        obj = 1;
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                }
                if (obj == null) {
                    eVar.R0();
                    if (e.f != null) {
                        if (eVar.b != null) {
                            c.j.a.d.b.e.b.o(new f(eVar, cVar));
                        }
                    }
                } else {
                    i iVar = eVar.b;
                    if (iVar == null) {
                        return;
                    }
                    try {
                        SQLiteStatement c = iVar.c();
                        if (c != null) {
                            try {
                                synchronized (c) {
                                    cVar.q(c);
                                    c.bindLong(cVar.f0 + 1, (long) cVar.g0());
                                    c.execute();
                                }
                            } catch (Throwable th2) {
                                th2.printStackTrace();
                            }
                        }
                    } catch (Throwable th22) {
                        th22.printStackTrace();
                    }
                }
            }
            return;
        }
    }

    /* compiled from: SqlDownloadCache */
    public class b implements Runnable {
        public final /* synthetic */ int a;

        public b(int i) {
            this.a = i;
        }

        public void run() {
            e.this.l(this.a);
            e.this.d(this.a);
        }
    }

    /* compiled from: SqlDownloadCache */
    public class c implements Runnable {
        public final /* synthetic */ SparseArray a;
        public final /* synthetic */ SparseArray b;
        public final /* synthetic */ d c;

        public c(SparseArray sparseArray, SparseArray sparseArray2, d dVar) {
            this.a = sparseArray;
            this.b = sparseArray2;
            this.c = dVar;
        }

        /* JADX WARNING: Removed duplicated region for block: B:70:0x00f0 A:{Catch:{ all -> 0x01c9 }} */
        /* JADX WARNING: Removed duplicated region for block: B:69:0x00e0 A:{Catch:{ all -> 0x01c9 }} */
        /* JADX WARNING: Removed duplicated region for block: B:34:0x0074 A:{Catch:{ all -> 0x01c9 }} */
        /* JADX WARNING: Removed duplicated region for block: B:37:0x007f A:{Catch:{ all -> 0x01c9 }} */
        /* JADX WARNING: Removed duplicated region for block: B:69:0x00e0 A:{Catch:{ all -> 0x01c9 }} */
        /* JADX WARNING: Removed duplicated region for block: B:70:0x00f0 A:{Catch:{ all -> 0x01c9 }} */
        /* JADX WARNING: Missing block: B:113:0x01a1, code skipped:
            if (r0 != null) goto L_0x0267;
     */
        /* JADX WARNING: Missing block: B:123:0x01ae, code skipped:
            if (r0 == null) goto L_0x0270;
     */
        /* JADX WARNING: Missing block: B:161:0x0259, code skipped:
            if (r0 == null) goto L_0x0270;
     */
        /* JADX WARNING: Missing block: B:171:0x0265, code skipped:
            if (r0 == null) goto L_0x0270;
     */
        /* JADX WARNING: Missing block: B:172:0x0267, code skipped:
            ((c.j.a.d.b.j.i) r0).a();
            r1.d.d = true;
     */
        /* JADX WARNING: Missing block: B:173:0x0270, code skipped:
            r1.d.L0(r8, r9);
     */
        /* JADX WARNING: Missing block: B:174:0x0275, code skipped:
            return;
     */
        /* JADX WARNING: Missing block: B:211:0x031e, code skipped:
            if (r0 == null) goto L_0x0335;
     */
        /* JADX WARNING: Missing block: B:221:0x032a, code skipped:
            if (r0 == null) goto L_0x0335;
     */
        /* JADX WARNING: Missing block: B:222:0x032c, code skipped:
            ((c.j.a.d.b.j.i) r0).a();
            r1.d.d = true;
     */
        /* JADX WARNING: Missing block: B:223:0x0335, code skipped:
            r1.d.L0(r8, r9);
     */
        public void run() {
            /*
            r20 = this;
            r1 = r20;
            r0 = c.j.a.d.b.c.e.this;
            r0.R0();
            r0 = c.j.a.d.b.c.e.f;
            if (r0 != 0) goto L_0x000c;
        L_0x000b:
            return;
        L_0x000c:
            r0 = r1.a;
            if (r0 != 0) goto L_0x0015;
        L_0x0010:
            r0 = new android.util.SparseArray;
            r0.<init>();
        L_0x0015:
            r8 = r0;
            r0 = r1.b;
            if (r0 != 0) goto L_0x001f;
        L_0x001a:
            r0 = new android.util.SparseArray;
            r0.<init>();
        L_0x001f:
            r9 = r0;
            r0 = c.j.a.d.b.e.b.A();
            r5 = new android.util.SparseArray;
            r5.<init>();
            r4 = new java.util.ArrayList;
            r4.<init>();
            r3 = new java.util.ArrayList;
            r3.<init>();
            r2 = 0;
            r10 = -3;
            r12 = 0;
            r13 = 1;
            r6 = c.j.a.d.b.c.e.f;	 Catch:{ all -> 0x01c9 }
            r7 = "SELECT * FROM downloader";
            r2 = r6.rawQuery(r7, r2);	 Catch:{ all -> 0x01c9 }
        L_0x003f:
            r6 = r2.moveToNext();	 Catch:{ all -> 0x01c9 }
            if (r6 == 0) goto L_0x0115;
        L_0x0045:
            r6 = new com.ss.android.socialbase.downloader.g.c;	 Catch:{ all -> 0x01c9 }
            r6.m4691init(r2);	 Catch:{ all -> 0x01c9 }
            r7 = r6.o0();	 Catch:{ all -> 0x01c9 }
            r14 = 4;
            r15 = 0;
            if (r7 == r14) goto L_0x0070;
        L_0x0053:
            r14 = 3;
            if (r7 == r14) goto L_0x0070;
        L_0x0056:
            r14 = -1;
            if (r7 == r14) goto L_0x0070;
        L_0x0059:
            r14 = 5;
            if (r7 == r14) goto L_0x0070;
        L_0x005c:
            r14 = 8;
            if (r7 == r14) goto L_0x0070;
        L_0x0060:
            if (r7 == r13) goto L_0x0065;
        L_0x0062:
            r14 = 2;
            if (r7 != r14) goto L_0x006e;
        L_0x0065:
            r17 = r6.I();	 Catch:{ all -> 0x01c9 }
            r7 = (r17 > r15 ? 1 : (r17 == r15 ? 0 : -1));
            if (r7 <= 0) goto L_0x006e;
        L_0x006d:
            goto L_0x0070;
        L_0x006e:
            r7 = 0;
            goto L_0x0071;
        L_0x0070:
            r7 = 1;
        L_0x0071:
            r14 = -5;
            if (r7 == 0) goto L_0x0077;
        L_0x0074:
            r6.b0(r14);	 Catch:{ all -> 0x01c9 }
        L_0x0077:
            r7 = r6.e;	 Catch:{ all -> 0x01c9 }
            r7 = android.text.TextUtils.isEmpty(r7);	 Catch:{ all -> 0x01c9 }
            if (r7 != 0) goto L_0x00dd;
        L_0x007f:
            r7 = r6.b;	 Catch:{ all -> 0x01c9 }
            r7 = android.text.TextUtils.isEmpty(r7);	 Catch:{ all -> 0x01c9 }
            if (r7 == 0) goto L_0x0088;
        L_0x0087:
            goto L_0x00dd;
        L_0x0088:
            r7 = r6.o0();	 Catch:{ all -> 0x01c9 }
            r11 = 11;
            if (r7 != r13) goto L_0x009a;
        L_0x0090:
            r18 = r6.I();	 Catch:{ all -> 0x01c9 }
            r7 = (r18 > r15 ? 1 : (r18 == r15 ? 0 : -1));
            if (r7 > 0) goto L_0x009a;
        L_0x0098:
            r7 = 1;
            goto L_0x00b0;
        L_0x009a:
            r7 = r6.o0();	 Catch:{ all -> 0x01c9 }
            if (r7 == r10) goto L_0x00af;
        L_0x00a0:
            r7 = r6.o0();	 Catch:{ all -> 0x01c9 }
            if (r7 == r11) goto L_0x00af;
        L_0x00a6:
            r7 = r6.R();	 Catch:{ all -> 0x01c9 }
            if (r7 != 0) goto L_0x00af;
        L_0x00ac:
            r6.P();	 Catch:{ all -> 0x01c9 }
        L_0x00af:
            r7 = 0;
        L_0x00b0:
            r15 = r6.o0();	 Catch:{ all -> 0x01c9 }
            if (r15 != r11) goto L_0x00b9;
        L_0x00b6:
            r6.b0(r14);	 Catch:{ all -> 0x01c9 }
        L_0x00b9:
            r11 = r6.o0();	 Catch:{ all -> 0x01c9 }
            r14 = r6.e;	 Catch:{ all -> 0x01c9 }
            r15 = r6.b;	 Catch:{ all -> 0x01c9 }
            r16 = c.j.a.d.b.n.a.a;	 Catch:{ all -> 0x01c9 }
            if (r11 != r10) goto L_0x00cd;
        L_0x00c5:
            r11 = c.j.a.d.b.n.a.R(r14, r15);	 Catch:{ all -> 0x01c9 }
            if (r11 != 0) goto L_0x00cd;
        L_0x00cb:
            r11 = 1;
            goto L_0x00ce;
        L_0x00cd:
            r11 = 0;
        L_0x00ce:
            if (r11 == 0) goto L_0x00de;
        L_0x00d0:
            r11 = 33554432; // 0x2000000 float:9.403955E-38 double:1.6578092E-316;
            r11 = c.j.a.c.y.a.i.s(r11);	 Catch:{ all -> 0x01c9 }
            if (r11 == 0) goto L_0x00d9;
        L_0x00d8:
            goto L_0x00dd;
        L_0x00d9:
            r6.Q();	 Catch:{ all -> 0x01c9 }
            goto L_0x00de;
        L_0x00dd:
            r7 = 1;
        L_0x00de:
            if (r7 == 0) goto L_0x00f0;
        L_0x00e0:
            r7 = r6.g0();	 Catch:{ all -> 0x01c9 }
            r7 = java.lang.Integer.valueOf(r7);	 Catch:{ all -> 0x01c9 }
            r4.add(r7);	 Catch:{ all -> 0x01c9 }
            r3.add(r6);	 Catch:{ all -> 0x01c9 }
            goto L_0x003f;
        L_0x00f0:
            r7 = r6.g0();	 Catch:{ all -> 0x01c9 }
            if (r0 == 0) goto L_0x00ff;
        L_0x00f6:
            r11 = r6.d;	 Catch:{ all -> 0x01c9 }
            r14 = r6.e;	 Catch:{ all -> 0x01c9 }
            r11 = r0.a(r11, r14);	 Catch:{ all -> 0x01c9 }
            goto L_0x0100;
        L_0x00ff:
            r11 = 0;
        L_0x0100:
            if (r11 == r7) goto L_0x0107;
        L_0x0102:
            r6.a = r11;	 Catch:{ all -> 0x01c9 }
            r5.put(r7, r6);	 Catch:{ all -> 0x01c9 }
        L_0x0107:
            monitor-enter(r8);	 Catch:{ all -> 0x01c9 }
            r7 = r6.g0();	 Catch:{ all -> 0x0112 }
            r8.put(r7, r6);	 Catch:{ all -> 0x0112 }
            monitor-exit(r8);	 Catch:{ all -> 0x0112 }
            goto L_0x003f;
        L_0x0112:
            r0 = move-exception;
            monitor-exit(r8);	 Catch:{ all -> 0x0112 }
            throw r0;	 Catch:{ all -> 0x01c9 }
        L_0x0115:
            r0 = new java.io.Closeable[r13];
            r0[r12] = r2;
            c.j.a.d.b.n.a.q(r0);
            r0 = c.j.a.d.b.c.e.this;
            c.j.a.d.b.c.e.P0(r0, r3);
            r2 = c.j.a.d.b.c.e.this;
            r6 = r8;
            r7 = r9;
            c.j.a.d.b.c.e.Q0(r2, r3, r4, r5, r6, r7);
            monitor-enter(r8);	 Catch:{ all -> 0x01a8 }
            r0 = new java.util.ArrayList;	 Catch:{ all -> 0x01a5 }
            r0.<init>();	 Catch:{ all -> 0x01a5 }
        L_0x012e:
            r2 = r8.size();	 Catch:{ all -> 0x01a5 }
            if (r12 >= r2) goto L_0x0186;
        L_0x0134:
            r2 = r8.keyAt(r12);	 Catch:{ all -> 0x01a5 }
            if (r2 == 0) goto L_0x0183;
        L_0x013a:
            r2 = r8.get(r2);	 Catch:{ all -> 0x01a5 }
            r2 = (com.ss.android.socialbase.downloader.g.c) r2;	 Catch:{ all -> 0x01a5 }
            r3 = 8192; // 0x2000 float:1.14794E-41 double:4.0474E-320;
            r4 = c.j.a.c.y.a.i.s(r3);	 Catch:{ all -> 0x01a5 }
            if (r4 == 0) goto L_0x0169;
        L_0x0148:
            if (r2 == 0) goto L_0x0183;
        L_0x014a:
            r3 = r2.S();	 Catch:{ all -> 0x01a5 }
            if (r3 != 0) goto L_0x0183;
        L_0x0150:
            r3 = r2.o0();	 Catch:{ all -> 0x01a5 }
            if (r3 == r10) goto L_0x0183;
        L_0x0156:
            r3 = r2.g0();	 Catch:{ all -> 0x01a5 }
            r3 = java.lang.Integer.valueOf(r3);	 Catch:{ all -> 0x01a5 }
            r0.add(r3);	 Catch:{ all -> 0x01a5 }
            r2 = r2.g0();	 Catch:{ all -> 0x01a5 }
            r9.remove(r2);	 Catch:{ all -> 0x01a5 }
            goto L_0x0183;
        L_0x0169:
            if (r2 == 0) goto L_0x0183;
        L_0x016b:
            r3 = r2.S();	 Catch:{ all -> 0x01a5 }
            if (r3 != 0) goto L_0x0183;
        L_0x0171:
            r3 = r2.g0();	 Catch:{ all -> 0x01a5 }
            r3 = java.lang.Integer.valueOf(r3);	 Catch:{ all -> 0x01a5 }
            r0.add(r3);	 Catch:{ all -> 0x01a5 }
            r2 = r2.g0();	 Catch:{ all -> 0x01a5 }
            r9.remove(r2);	 Catch:{ all -> 0x01a5 }
        L_0x0183:
            r12 = r12 + 1;
            goto L_0x012e;
        L_0x0186:
            r0 = r0.iterator();	 Catch:{ all -> 0x01a5 }
        L_0x018a:
            r2 = r0.hasNext();	 Catch:{ all -> 0x01a5 }
            if (r2 == 0) goto L_0x019e;
        L_0x0190:
            r2 = r0.next();	 Catch:{ all -> 0x01a5 }
            r2 = (java.lang.Integer) r2;	 Catch:{ all -> 0x01a5 }
            r2 = r2.intValue();	 Catch:{ all -> 0x01a5 }
            r8.remove(r2);	 Catch:{ all -> 0x01a5 }
            goto L_0x018a;
        L_0x019e:
            monitor-exit(r8);	 Catch:{ all -> 0x01a5 }
            r0 = r1.c;
            if (r0 == 0) goto L_0x0270;
        L_0x01a3:
            goto L_0x0267;
        L_0x01a5:
            r0 = move-exception;
            monitor-exit(r8);	 Catch:{ all -> 0x01a5 }
            throw r0;	 Catch:{ all -> 0x01a8 }
        L_0x01a8:
            r0 = move-exception;
            r0.printStackTrace();	 Catch:{ all -> 0x01b2 }
            r0 = r1.c;
            if (r0 == 0) goto L_0x0270;
        L_0x01b0:
            goto L_0x0267;
        L_0x01b2:
            r0 = move-exception;
            r2 = r0;
            r0 = r1.c;
            if (r0 == 0) goto L_0x01c3;
        L_0x01b8:
            r0 = r1.c;
            r0 = (c.j.a.d.b.j.i) r0;
            r0.a();
            r0 = c.j.a.d.b.c.e.this;
            r0.d = r13;
        L_0x01c3:
            r0 = c.j.a.d.b.c.e.this;
            r0.L0(r8, r9);
            throw r2;
        L_0x01c9:
            r0 = move-exception;
            r0.printStackTrace();	 Catch:{ all -> 0x028d }
            r0 = new java.io.Closeable[r13];
            r0[r12] = r2;
            c.j.a.d.b.n.a.q(r0);
            r0 = c.j.a.d.b.c.e.this;
            c.j.a.d.b.c.e.P0(r0, r3);
            r2 = c.j.a.d.b.c.e.this;
            r6 = r8;
            r7 = r9;
            c.j.a.d.b.c.e.Q0(r2, r3, r4, r5, r6, r7);
            monitor-enter(r8);	 Catch:{ all -> 0x025f }
            r0 = new java.util.ArrayList;	 Catch:{ all -> 0x025c }
            r0.<init>();	 Catch:{ all -> 0x025c }
        L_0x01e6:
            r2 = r8.size();	 Catch:{ all -> 0x025c }
            if (r12 >= r2) goto L_0x023e;
        L_0x01ec:
            r2 = r8.keyAt(r12);	 Catch:{ all -> 0x025c }
            if (r2 == 0) goto L_0x023b;
        L_0x01f2:
            r2 = r8.get(r2);	 Catch:{ all -> 0x025c }
            r2 = (com.ss.android.socialbase.downloader.g.c) r2;	 Catch:{ all -> 0x025c }
            r3 = 8192; // 0x2000 float:1.14794E-41 double:4.0474E-320;
            r4 = c.j.a.c.y.a.i.s(r3);	 Catch:{ all -> 0x025c }
            if (r4 == 0) goto L_0x0221;
        L_0x0200:
            if (r2 == 0) goto L_0x023b;
        L_0x0202:
            r3 = r2.S();	 Catch:{ all -> 0x025c }
            if (r3 != 0) goto L_0x023b;
        L_0x0208:
            r3 = r2.o0();	 Catch:{ all -> 0x025c }
            if (r3 == r10) goto L_0x023b;
        L_0x020e:
            r3 = r2.g0();	 Catch:{ all -> 0x025c }
            r3 = java.lang.Integer.valueOf(r3);	 Catch:{ all -> 0x025c }
            r0.add(r3);	 Catch:{ all -> 0x025c }
            r2 = r2.g0();	 Catch:{ all -> 0x025c }
            r9.remove(r2);	 Catch:{ all -> 0x025c }
            goto L_0x023b;
        L_0x0221:
            if (r2 == 0) goto L_0x023b;
        L_0x0223:
            r3 = r2.S();	 Catch:{ all -> 0x025c }
            if (r3 != 0) goto L_0x023b;
        L_0x0229:
            r3 = r2.g0();	 Catch:{ all -> 0x025c }
            r3 = java.lang.Integer.valueOf(r3);	 Catch:{ all -> 0x025c }
            r0.add(r3);	 Catch:{ all -> 0x025c }
            r2 = r2.g0();	 Catch:{ all -> 0x025c }
            r9.remove(r2);	 Catch:{ all -> 0x025c }
        L_0x023b:
            r12 = r12 + 1;
            goto L_0x01e6;
        L_0x023e:
            r0 = r0.iterator();	 Catch:{ all -> 0x025c }
        L_0x0242:
            r2 = r0.hasNext();	 Catch:{ all -> 0x025c }
            if (r2 == 0) goto L_0x0256;
        L_0x0248:
            r2 = r0.next();	 Catch:{ all -> 0x025c }
            r2 = (java.lang.Integer) r2;	 Catch:{ all -> 0x025c }
            r2 = r2.intValue();	 Catch:{ all -> 0x025c }
            r8.remove(r2);	 Catch:{ all -> 0x025c }
            goto L_0x0242;
        L_0x0256:
            monitor-exit(r8);	 Catch:{ all -> 0x025c }
            r0 = r1.c;
            if (r0 == 0) goto L_0x0270;
        L_0x025b:
            goto L_0x0267;
        L_0x025c:
            r0 = move-exception;
            monitor-exit(r8);	 Catch:{ all -> 0x025c }
            throw r0;	 Catch:{ all -> 0x025f }
        L_0x025f:
            r0 = move-exception;
            r0.printStackTrace();	 Catch:{ all -> 0x0276 }
            r0 = r1.c;
            if (r0 == 0) goto L_0x0270;
        L_0x0267:
            r0 = (c.j.a.d.b.j.i) r0;
            r0.a();
            r0 = c.j.a.d.b.c.e.this;
            r0.d = r13;
        L_0x0270:
            r0 = c.j.a.d.b.c.e.this;
            r0.L0(r8, r9);
            return;
        L_0x0276:
            r0 = move-exception;
            r2 = r0;
            r0 = r1.c;
            if (r0 == 0) goto L_0x0287;
        L_0x027c:
            r0 = r1.c;
            r0 = (c.j.a.d.b.j.i) r0;
            r0.a();
            r0 = c.j.a.d.b.c.e.this;
            r0.d = r13;
        L_0x0287:
            r0 = c.j.a.d.b.c.e.this;
            r0.L0(r8, r9);
            throw r2;
        L_0x028d:
            r0 = move-exception;
            r11 = r0;
            r0 = new java.io.Closeable[r13];
            r0[r12] = r2;
            c.j.a.d.b.n.a.q(r0);
            r0 = c.j.a.d.b.c.e.this;
            c.j.a.d.b.c.e.P0(r0, r3);
            r2 = c.j.a.d.b.c.e.this;
            r6 = r8;
            r7 = r9;
            c.j.a.d.b.c.e.Q0(r2, r3, r4, r5, r6, r7);
            monitor-enter(r8);	 Catch:{ all -> 0x0324 }
            r0 = new java.util.ArrayList;	 Catch:{ all -> 0x0321 }
            r0.<init>();	 Catch:{ all -> 0x0321 }
        L_0x02a8:
            r2 = r8.size();	 Catch:{ all -> 0x0321 }
            if (r12 >= r2) goto L_0x0303;
        L_0x02ae:
            r2 = r8.keyAt(r12);	 Catch:{ all -> 0x0321 }
            if (r2 == 0) goto L_0x02fe;
        L_0x02b4:
            r2 = r8.get(r2);	 Catch:{ all -> 0x0321 }
            r2 = (com.ss.android.socialbase.downloader.g.c) r2;	 Catch:{ all -> 0x0321 }
            r3 = 8192; // 0x2000 float:1.14794E-41 double:4.0474E-320;
            r4 = c.j.a.c.y.a.i.s(r3);	 Catch:{ all -> 0x0321 }
            if (r4 == 0) goto L_0x02e3;
        L_0x02c2:
            if (r2 == 0) goto L_0x0300;
        L_0x02c4:
            r4 = r2.S();	 Catch:{ all -> 0x0321 }
            if (r4 != 0) goto L_0x0300;
        L_0x02ca:
            r4 = r2.o0();	 Catch:{ all -> 0x0321 }
            if (r4 == r10) goto L_0x0300;
        L_0x02d0:
            r4 = r2.g0();	 Catch:{ all -> 0x0321 }
            r4 = java.lang.Integer.valueOf(r4);	 Catch:{ all -> 0x0321 }
            r0.add(r4);	 Catch:{ all -> 0x0321 }
            r2 = r2.g0();	 Catch:{ all -> 0x0321 }
            r9.remove(r2);	 Catch:{ all -> 0x0321 }
            goto L_0x0300;
        L_0x02e3:
            if (r2 == 0) goto L_0x0300;
        L_0x02e5:
            r4 = r2.S();	 Catch:{ all -> 0x0321 }
            if (r4 != 0) goto L_0x0300;
        L_0x02eb:
            r4 = r2.g0();	 Catch:{ all -> 0x0321 }
            r4 = java.lang.Integer.valueOf(r4);	 Catch:{ all -> 0x0321 }
            r0.add(r4);	 Catch:{ all -> 0x0321 }
            r2 = r2.g0();	 Catch:{ all -> 0x0321 }
            r9.remove(r2);	 Catch:{ all -> 0x0321 }
            goto L_0x0300;
        L_0x02fe:
            r3 = 8192; // 0x2000 float:1.14794E-41 double:4.0474E-320;
        L_0x0300:
            r12 = r12 + 1;
            goto L_0x02a8;
        L_0x0303:
            r0 = r0.iterator();	 Catch:{ all -> 0x0321 }
        L_0x0307:
            r2 = r0.hasNext();	 Catch:{ all -> 0x0321 }
            if (r2 == 0) goto L_0x031b;
        L_0x030d:
            r2 = r0.next();	 Catch:{ all -> 0x0321 }
            r2 = (java.lang.Integer) r2;	 Catch:{ all -> 0x0321 }
            r2 = r2.intValue();	 Catch:{ all -> 0x0321 }
            r8.remove(r2);	 Catch:{ all -> 0x0321 }
            goto L_0x0307;
        L_0x031b:
            monitor-exit(r8);	 Catch:{ all -> 0x0321 }
            r0 = r1.c;
            if (r0 == 0) goto L_0x0335;
        L_0x0320:
            goto L_0x032c;
        L_0x0321:
            r0 = move-exception;
            monitor-exit(r8);	 Catch:{ all -> 0x0321 }
            throw r0;	 Catch:{ all -> 0x0324 }
        L_0x0324:
            r0 = move-exception;
            r0.printStackTrace();	 Catch:{ all -> 0x033b }
            r0 = r1.c;
            if (r0 == 0) goto L_0x0335;
        L_0x032c:
            r0 = (c.j.a.d.b.j.i) r0;
            r0.a();
            r0 = c.j.a.d.b.c.e.this;
            r0.d = r13;
        L_0x0335:
            r0 = c.j.a.d.b.c.e.this;
            r0.L0(r8, r9);
            throw r11;
        L_0x033b:
            r0 = move-exception;
            r2 = r0;
            r0 = r1.c;
            if (r0 == 0) goto L_0x034c;
        L_0x0341:
            r0 = r1.c;
            r0 = (c.j.a.d.b.j.i) r0;
            r0.a();
            r0 = c.j.a.d.b.c.e.this;
            r0.d = r13;
        L_0x034c:
            r0 = c.j.a.d.b.c.e.this;
            r0.L0(r8, r9);
            throw r2;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.c.e$c.run():void");
        }
    }

    /* compiled from: SqlDownloadCache */
    public class d implements Runnable {
        public void run() {
            e eVar = e.this;
            synchronized (eVar) {
                try {
                    e.f.beginTransaction();
                    e.f.delete("downloader", null, null);
                    e.f.delete("downloadChunk", null, null);
                    e.f.setTransactionSuccessful();
                } catch (Throwable th) {
                    eVar.S0();
                }
                eVar.S0();
            }
        }
    }

    /* compiled from: SqlDownloadCache */
    public class e implements Runnable {
        public final /* synthetic */ int a;
        public final /* synthetic */ ContentValues b;

        public e(int i, ContentValues contentValues) {
            this.a = i;
            this.b = contentValues;
        }

        public void run() {
            e eVar = e.this;
            int i = this.a;
            ContentValues contentValues = this.b;
            Objects.requireNonNull(eVar);
            int i2 = 10;
            while (e.f.isDbLockedByCurrentThread()) {
                try {
                    i2--;
                    if (i2 >= 0) {
                        Thread.sleep(5);
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                    return;
                }
            }
            try {
                e.f.update("downloader", contentValues, "_id = ? ", new String[]{String.valueOf(i)});
            } catch (Throwable th2) {
                th2.printStackTrace();
            }
        }
    }

    /* compiled from: SqlDownloadCache */
    public class f implements Runnable {
        public final /* synthetic */ int a;

        public f(int i) {
            this.a = i;
        }

        public void run() {
            try {
                e.this.K0(this.a, e.this.c.b());
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    /* compiled from: SqlDownloadCache */
    public class g implements Runnable {
        public final /* synthetic */ com.ss.android.socialbase.downloader.g.b a;

        public g(com.ss.android.socialbase.downloader.g.b bVar) {
            this.a = bVar;
        }

        public void run() {
            try {
                SQLiteStatement a = e.this.c.a();
                e eVar = e.this;
                com.ss.android.socialbase.downloader.g.b bVar = this.a;
                Objects.requireNonNull(eVar);
                if (bVar != null && a != null) {
                    try {
                        synchronized (a) {
                            bVar.b(a);
                            a.executeInsert();
                        }
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                }
            } catch (Throwable th2) {
                th2.printStackTrace();
            }
        }
    }

    /* compiled from: SqlDownloadCache */
    public class h implements Runnable {
        public final /* synthetic */ int a;
        public final /* synthetic */ int b;
        public final /* synthetic */ long c;

        public h(int i, int i2, long j) {
            this.a = i;
            this.b = i2;
            this.c = j;
        }

        public void run() {
            try {
                e.O0(e.this, this.a, this.b, this.c, e.this.c.c());
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    /* compiled from: SqlDownloadCache */
    public class i implements Runnable {
        public final /* synthetic */ int a;
        public final /* synthetic */ int b;
        public final /* synthetic */ int c;
        public final /* synthetic */ long d;

        public i(int i, int i2, int i3, long j) {
            this.a = i;
            this.b = i2;
            this.c = i3;
            this.d = j;
        }

        public void run() {
            try {
                e.N0(e.this, this.a, this.b, this.c, this.d, e.this.c.c());
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    /* compiled from: SqlDownloadCache */
    public class j implements Runnable {
        public final /* synthetic */ int a;
        public final /* synthetic */ int b;
        public final /* synthetic */ int c;
        public final /* synthetic */ int d;

        public j(int i, int i2, int i3, int i4) {
            this.a = i;
            this.b = i2;
            this.c = i3;
            this.d = i4;
        }

        public void run() {
            try {
                e.M0(e.this, this.a, this.b, this.c, this.d, e.this.c.c());
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public static void M0(e eVar, int i, int i2, int i3, int i4, SQLiteStatement sQLiteStatement) {
        Objects.requireNonNull(eVar);
        try {
            synchronized (sQLiteStatement) {
                ContentValues contentValues = new ContentValues();
                contentValues.put("chunkIndex", Integer.valueOf(i4));
                f.update("downloadChunk", contentValues, "_id = ? AND chunkIndex = ? AND hostChunkIndex = ?", new String[]{Integer.toString(i), Integer.toString(i2), Integer.toString(i3)});
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public static void N0(e eVar, int i, int i2, int i3, long j, SQLiteStatement sQLiteStatement) {
        Objects.requireNonNull(eVar);
        try {
            synchronized (sQLiteStatement) {
                ContentValues contentValues = new ContentValues();
                contentValues.put("curOffset", Long.valueOf(j));
                f.update("downloadChunk", contentValues, "_id = ? AND chunkIndex = ? AND hostChunkIndex = ?", new String[]{Integer.toString(i), Integer.toString(i2), Integer.toString(i3)});
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public static void O0(e eVar, int i, int i2, long j, SQLiteStatement sQLiteStatement) {
        Objects.requireNonNull(eVar);
        try {
            synchronized (sQLiteStatement) {
                ContentValues contentValues = new ContentValues();
                contentValues.put("curOffset", Long.valueOf(j));
                f.update("downloadChunk", contentValues, "_id = ? AND chunkIndex = ?", new String[]{Integer.toString(i), Integer.toString(i2)});
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public static void P0(e eVar, List list) {
        Objects.requireNonNull(eVar);
        try {
            for (com.ss.android.socialbase.downloader.g.c cVar : list) {
                if (cVar != null && cVar.X()) {
                    c.j.a.d.b.n.a.C(cVar);
                }
            }
        } catch (Throwable unused) {
        }
    }

    public static void Q0(e eVar, List list, List list2, SparseArray sparseArray, SparseArray sparseArray2, SparseArray sparseArray3) {
        e eVar2 = eVar;
        SparseArray sparseArray4 = sparseArray;
        SparseArray sparseArray5 = sparseArray2;
        Objects.requireNonNull(eVar);
        int size = sparseArray.size();
        if (size >= 0 && f != null) {
            synchronized (f) {
                try {
                    int i;
                    f.beginTransaction();
                    int i2 = 0;
                    if (!list.isEmpty()) {
                        if (c.j.a.d.b.l.a.f.k("clear_invalid_task_error", false)) {
                            String[] strArr = new String[list.size()];
                            for (i = 0; i < list.size(); i++) {
                                strArr[i] = String.valueOf(list.get(i));
                            }
                            List list3 = list;
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.append("CAST(_id AS TEXT) IN (");
                            stringBuilder.append(new String(new char[(list.size() - 1)]).replace("\u0000", "?,"));
                            stringBuilder.append("?)");
                            String stringBuilder2 = stringBuilder.toString();
                            f.delete("downloader", stringBuilder2, strArr);
                            f.delete("downloadChunk", stringBuilder2, strArr);
                        } else {
                            String join = TextUtils.join(", ", list2);
                            f.delete("downloader", "_id IN (?)", new String[]{join});
                            f.delete("downloadChunk", "_id IN (?)", new String[]{join});
                        }
                    }
                    for (int i3 = 0; i3 < size; i3++) {
                        i = sparseArray4.keyAt(i3);
                        com.ss.android.socialbase.downloader.g.c cVar = (com.ss.android.socialbase.downloader.g.c) sparseArray4.get(i);
                        f.delete("downloader", "_id = ?", new String[]{String.valueOf(i)});
                        f.insert("downloader", null, cVar.e0());
                        if (cVar.R > 1) {
                            ArrayList arrayList = (ArrayList) eVar2.c(i);
                            if (arrayList.size() > 0) {
                                f.delete("downloadChunk", "_id = ?", new String[]{String.valueOf(i)});
                                Iterator it = arrayList.iterator();
                                while (it.hasNext()) {
                                    com.ss.android.socialbase.downloader.g.b bVar = (com.ss.android.socialbase.downloader.g.b) it.next();
                                    bVar.a = cVar.g0();
                                    f.insert("downloadChunk", null, bVar.a());
                                }
                            }
                        }
                    }
                    synchronized (sparseArray2) {
                        int size2 = sparseArray2.size();
                        while (i2 < size2) {
                            size = ((com.ss.android.socialbase.downloader.g.c) sparseArray5.valueAt(i2)).g0();
                            List i4 = c.j.a.d.b.n.a.i(eVar2.c(size));
                            if (i4.size() > 0) {
                                sparseArray3.put(size, i4);
                            } else {
                                SparseArray sparseArray6 = sparseArray3;
                            }
                            i2++;
                        }
                    }
                    f.setTransactionSuccessful();
                } catch (Throwable th) {
                    try {
                        th.printStackTrace();
                    } catch (Throwable th2) {
                        Throwable th3 = th2;
                        eVar.S0();
                    }
                }
                try {
                    eVar.S0();
                } finally {
                }
            }
        }
    }

    public com.ss.android.socialbase.downloader.g.c C(int i, long j) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(-2));
        contentValues.put("curBytes", Long.valueOf(j));
        J0(i, contentValues);
        return null;
    }

    public void E(com.ss.android.socialbase.downloader.g.b bVar) {
        f(bVar);
    }

    public com.ss.android.socialbase.downloader.g.c I(int i, long j, String str, String str2) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(3));
        contentValues.put("totalBytes", Long.valueOf(j));
        contentValues.put("eTag", str);
        if (!TextUtils.isEmpty(str2)) {
            contentValues.put(RankingConst.RANKING_JGW_NAME, str2);
        }
        J0(i, contentValues);
        return null;
    }

    public final void J0(int i, ContentValues contentValues) {
        R0();
        if (f != null) {
            c.j.a.d.b.e.b.o(new e(i, contentValues));
        }
    }

    public final void K0(int i, SQLiteStatement sQLiteStatement) {
        if (sQLiteStatement != null) {
            try {
                synchronized (sQLiteStatement) {
                    sQLiteStatement.bindLong(1, (long) i);
                    sQLiteStatement.execute();
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public void L0(SparseArray<com.ss.android.socialbase.downloader.g.c> sparseArray, SparseArray<List<com.ss.android.socialbase.downloader.g.b>> sparseArray2) {
        try {
            HashMap h = c.j.a.d.b.n.a.h(sparseArray);
            HashMap h2 = c.j.a.d.b.n.a.h(sparseArray2);
            b bVar = this.e;
            if (bVar != null) {
                bVar.z0(h, h2);
            }
        } catch (Throwable unused) {
        }
    }

    public com.ss.android.socialbase.downloader.g.c O(int i, long j) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(-1));
        contentValues.put("curBytes", Long.valueOf(j));
        if (j > 0) {
            contentValues.put("isFirstDownload", Integer.valueOf(0));
        }
        J0(i, contentValues);
        return null;
    }

    public final void R0() {
        if (f == null) {
            synchronized (e.class) {
                if (f == null) {
                    try {
                        if (a.b == null) {
                            synchronized (a.class) {
                                if (a.b == null) {
                                    a.b = new a();
                                }
                            }
                        }
                        f = a.b.getWritableDatabase();
                        this.b = new i(f, "downloader", c.j.a.d.b.b.c.a, c.j.a.d.b.b.c.b);
                        this.c = new i(f, "downloadChunk", c.j.a.d.b.b.c.c, c.j.a.d.b.b.c.d);
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                }
            }
        }
    }

    public final void S0() {
        try {
            if (f != null && f.inTransaction()) {
                f.endTransaction();
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public void a() {
        try {
            c cVar = new c(null, null, null);
            ExecutorService u = c.j.a.d.b.e.b.u();
            if (u != null) {
                u.execute(cVar);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public com.ss.android.socialbase.downloader.g.c b(int i) {
        Throwable th;
        R0();
        if (f != null) {
            Cursor rawQuery;
            try {
                rawQuery = f.rawQuery(String.format("SELECT * FROM %s WHERE %s = ?", new Object[]{"downloader", "_id"}), new String[]{Integer.toString(i)});
                try {
                    if (rawQuery.moveToNext()) {
                        com.ss.android.socialbase.downloader.g.c cVar = new com.ss.android.socialbase.downloader.g.c(rawQuery);
                        c.j.a.d.b.n.a.q(rawQuery);
                        return cVar;
                    }
                    c.j.a.d.b.n.a.q(rawQuery);
                } catch (Throwable th2) {
                    th = th2;
                    try {
                        th.printStackTrace();
                        c.j.a.d.b.n.a.q(rawQuery);
                        return null;
                    } catch (Throwable th3) {
                        c.j.a.d.b.n.a.q(rawQuery);
                    }
                }
            } catch (Throwable th4) {
                th = th4;
                rawQuery = null;
                th.printStackTrace();
                c.j.a.d.b.n.a.q(rawQuery);
                return null;
            }
        }
        return null;
    }

    public List<com.ss.android.socialbase.downloader.g.c> b(String str) {
        return null;
    }

    public void b(com.ss.android.socialbase.downloader.g.c cVar) {
    }

    public List<com.ss.android.socialbase.downloader.g.b> c(int i) {
        ArrayList arrayList = new ArrayList();
        R0();
        if (f != null) {
            try {
                Cursor rawQuery = f.rawQuery(String.format("SELECT * FROM %s WHERE %s = ?", new Object[]{"downloadChunk", "_id"}), new String[]{Integer.toString(i)});
                while (rawQuery.moveToNext()) {
                    arrayList.add(new com.ss.android.socialbase.downloader.g.b(rawQuery));
                }
                c.j.a.d.b.n.a.q(rawQuery);
            } catch (Throwable th) {
                c.j.a.d.b.n.a.q(null);
            }
        }
        return arrayList;
    }

    public List<com.ss.android.socialbase.downloader.g.c> c(String str) {
        return null;
    }

    public void d(int i) {
        R0();
        if (f != null && this.c != null) {
            c.j.a.d.b.e.b.o(new f(i));
        }
    }

    public boolean d() {
        return false;
    }

    public com.ss.android.socialbase.downloader.g.c e(int i) {
        return null;
    }

    public void e0(b bVar) {
        this.e = bVar;
    }

    public void f(com.ss.android.socialbase.downloader.g.b bVar) {
        R0();
        if (f != null && this.c != null) {
            c.j.a.d.b.e.b.o(new g(bVar));
        }
    }

    public com.ss.android.socialbase.downloader.g.c g(int i) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(5));
        contentValues.put("isFirstDownload", Integer.valueOf(0));
        J0(i, contentValues);
        return null;
    }

    public com.ss.android.socialbase.downloader.g.c h(int i) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(1));
        J0(i, contentValues);
        return null;
    }

    public void i(int i, List<com.ss.android.socialbase.downloader.g.b> list) {
    }

    public List<com.ss.android.socialbase.downloader.g.c> j(String str) {
        return null;
    }

    public void k(int i, int i2, long j) {
        R0();
        if (i != 0 && i2 >= 0 && j >= 0 && f != null && this.c != null) {
            c.j.a.d.b.e.b.o(new h(i, i2, j));
        }
    }

    public boolean l(int i) {
        R0();
        if (f != null) {
            i iVar = this.b;
            if (iVar != null) {
                try {
                    K0(i, iVar.b());
                    return true;
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        }
        return false;
    }

    public void m(int i, int i2, int i3, long j) {
        R0();
        if (i != 0 && i2 >= 0 && i3 >= 0 && j >= 0 && f != null && this.c != null) {
            c.j.a.d.b.e.b.o(new i(i, i2, i3, j));
        }
    }

    public void n(int i, int i2, int i3, int i4) {
        R0();
        if (i != 0 && i3 >= 0 && i4 != i2 && i4 >= 0 && f != null && this.c != null) {
            c.j.a.d.b.e.b.o(new j(i, i2, i3, i4));
        }
    }

    public com.ss.android.socialbase.downloader.g.c o(int i) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(-7));
        J0(i, contentValues);
        return null;
    }

    public com.ss.android.socialbase.downloader.g.c t(int i, long j) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(-3));
        contentValues.put("curBytes", Long.valueOf(j));
        Integer valueOf = Integer.valueOf(0);
        contentValues.put("isFirstDownload", valueOf);
        contentValues.put("isFirstSuccess", valueOf);
        J0(i, contentValues);
        return null;
    }

    public void y0(SparseArray<com.ss.android.socialbase.downloader.g.c> sparseArray, SparseArray<List<com.ss.android.socialbase.downloader.g.b>> sparseArray2, d dVar) {
        try {
            c cVar = new c(sparseArray, sparseArray2, dVar);
            ExecutorService u = c.j.a.d.b.e.b.u();
            if (u != null) {
                u.execute(cVar);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public void d(int i, List<com.ss.android.socialbase.downloader.g.b> list) {
        try {
            d(i);
            if (list != null) {
                for (com.ss.android.socialbase.downloader.g.b bVar : list) {
                    if (bVar != null) {
                        f(bVar);
                        if (bVar.j()) {
                            for (com.ss.android.socialbase.downloader.g.b f : bVar.i) {
                                f(f);
                            }
                        }
                    }
                }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public boolean f(int i) {
        c.j.a.d.b.e.b.o(new b(i));
        return true;
    }

    public List<com.ss.android.socialbase.downloader.g.c> a(String str) {
        R0();
        ArrayList arrayList = new ArrayList();
        if (f != null) {
            try {
                Cursor rawQuery = f.rawQuery(String.format("SELECT * FROM %s WHERE %s = ?", new Object[]{"downloader", HwPayConstant.KEY_URL}), new String[]{str});
                if (rawQuery.moveToNext()) {
                    arrayList.add(new com.ss.android.socialbase.downloader.g.c(rawQuery));
                }
                c.j.a.d.b.n.a.q(rawQuery);
            } catch (Throwable th) {
                c.j.a.d.b.n.a.q(null);
            }
        }
        return arrayList;
    }

    public void b() {
        R0();
        if (f != null) {
            c.j.a.d.b.e.b.o(new d());
        }
    }

    public boolean c() {
        return this.d;
    }

    public com.ss.android.socialbase.downloader.g.c a(int i, int i2) {
        R0();
        if (f == null) {
            return null;
        }
        int i3 = 10;
        while (f.isDbLockedByCurrentThread()) {
            try {
                i3--;
                if (i3 < 0) {
                    break;
                }
                Thread.sleep(5);
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("chunkCount", Integer.valueOf(i2));
        f.update("downloader", contentValues, "_id = ? ", new String[]{Integer.toString(i)});
        return null;
    }

    public boolean a(com.ss.android.socialbase.downloader.g.c cVar) {
        R0();
        if (cVar == null || f == null) {
            return false;
        }
        c.j.a.d.b.e.b.o(new a(cVar));
        return true;
    }

    public com.ss.android.socialbase.downloader.g.c a(int i, long j) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("status", Integer.valueOf(4));
        contentValues.put("curBytes", Long.valueOf(j));
        J0(i, contentValues);
        return null;
    }
}
